package com.woniu.tms.manage.service.impl;

import com.woniu.tms.entity.UserRole;
import com.woniu.tms.entity.UserRoleExample;
import com.woniu.tms.manage.service.UserRoleService;
import com.woniu.tms.mapper.UserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    UserRoleMapper userRoleMapper;

    @Override
    public void add(Integer uid, Integer[] rids) {
        for (Integer rid : rids) {
            UserRole userRole = new UserRole();
            userRole.setRid(rid);
            userRole.setUid(uid);
            userRoleMapper.insert(userRole);
        }
    }

    @Override
    public void delete(Integer uid, Integer[] rids2) {
        UserRoleExample example = new UserRoleExample();
        UserRoleExample.Criteria criteria = example.createCriteria();
        List<Integer> list = Arrays.asList(rids2);
        criteria.andUidEqualTo(uid);
        criteria.andRidIn(list);
        userRoleMapper.deleteByExample(example);
    }

}
